﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 17.03.2008
 * Zeit: 17:32
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Gamadus.Designer
{
	/// <summary>
	/// The different types of Resources shown in the Resource Tree
	/// </summary>
	public enum ResourceType
	{
		Sprite,
		Background,
		Object,
		Room,
		Class,
		Unknown
	}
	/// <summary>
	/// Description of Resource.
	/// </summary>
	public class Resource
	{
		public string Name
		{
			get
			{
				return name;
			}
			set
			{
				if(ResourceMgr.Instance.IsValidName(value))
				{
					name = value;
				}
				Node.Text = name;
				if(editWindow != null)
					editWindow.UpdateEditForm();
			}
		}
		protected string name;
		public TreeNode Node;
		protected IEditWindow editWindow;
		
		private Dictionary<string,object> settings = new Dictionary<string,object>();
		public Dictionary<string,object> Settings
		{
			get
			{
				return settings;
			}
		}
		
		protected ResourceType type;
		public ResourceType Type
		{
		
			get
			{
				return type;
			}
		}
		private int id;
		public int ID
		{
			get
			{
				return id;
			}
		}
		
		public Resource(int id)
		{
			this.type = ResourceType.Unknown;
			this.id = id;
		}
		public void ShowEditWindow()
		{
			if(editWindow == null)
			{
				editWindow = showEditForm();
				ResourceMgr.Instance.editWindows.Add(editWindow);
			}
			else
			{
				(editWindow as Form).Activate();
			}
		}
		public void CloseEditorHandle(bool didChanges)
		{
			ResourceMgr.Instance.editWindows.Remove(editWindow);
			editWindow = null;
			if(didChanges)
			ResourceMgr.Instance.DidChanges = true;
		}
		
		protected virtual IEditWindow showEditForm()
		{
			throw new NotImplementedException();
		}
		
		protected void CloseEditForm()
		{
			editWindow.Close();
		}
		
		public virtual void WriteXml(System.Xml.XmlTextWriter xml)
		{
			throw new NotImplementedException();
		}
		public virtual void ReadXml(System.Xml.XmlElement element)
		{
			throw new NotImplementedException();
		}
	}
	
	public class Sprite : Resource
	{
		public Sprite(int id):base(id)
		{
			this.type = ResourceType.Sprite;
		}
	}
	
	public class Background : Resource
	{
		public Background(int id):base(id)
		{
			this.type = ResourceType.Background;
		}
	}
	
	public class ClassResource : Resource
	{
		public ClassResource(int id):base(id)
		{
			this.type = ResourceType.Class;
		}
	}
}
